import request from '@/utils/request'

// 获取用户帖子列表
export const getPersonPostListServer = (
  state,
  feed,
  current = 1,
  pageSize = 100
) =>
  request.get(
    `/post/my/${state}/${feed}?current=${current}&pageSize=${pageSize}`
  )

// 发布帖子
export const postPublishServer = ({
  title,
  content,
  longitude,
  latitude,
  img
}) => {
  const formData = new FormData()
  formData.append('files', img)
  request.put(
    `/post/publish?title=${title}&content=${content}&longitude=${longitude}&latitude=${latitude}`,
    formData
  )
}
// export const postPublishServer = (data) => {
//   const formData = new FormData()
//   // formData.append('title', title)
//   // formData.append('content', content)
//   // formData.append('longitude', longitude)
//   // formData.append('latitude', latitude)
//   formData.append('files', data)
//   request.post(`/post/publish`, formData)
// }

// 删除帖子
export const deletePostServer = (postId) => request.delete(`/post/${postId}`)

// 喂养动物
export const postFeedServer = (postId) => request.put(`/post/feed/${postId}`)

// 获取帖子评论
export const getPostCommentServer = (postId, current = 1, pageSize = 100) =>
  request.get(`/post/comment/${postId}?current=${current}&pageSize=${pageSize}`)

// 添加帖子评论
export const addPostCommentServer = (postId, content, fatherId = 0) =>
  request.post('/post/comment', { postId, content, fatherId })

// 删除帖子评论
export const deletePostCommentServer = (commentId) =>
  request.delete(`/post/comment/my/${commentId}`)

/**
 * 管理员功能
 */

// 获取全部用户帖子列表
export const getAdminPersonPostListServer = (
  state = 2,
  feed,
  current = 1,
  pageSize = 12
) =>
  request.get(
    `/post/admin/${state}/${feed}?current=${current}&pageSize=${pageSize}`
  )

// 修改帖子审核状态
export const updateAdminPostListServer = (post_id, state) =>
  request.put(`/post/admin/modify/${post_id}/${state}`)

// 删除帖子
export const deleteAdminPostServer = (postId) =>
  request.delete(`/post/admin/${postId}`)
